/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.event.thuoc;

import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import model.dao.ncc.NhaCungCapDAO;
import model.entity.NhaCungCap;
import org.hibernate.HibernateException;

/**
 *
 * @author nv_ca@live.com
 */
public class ThuocThemNCCDlg_evt {

    public static final void btnCloseActionPerformed(JDialog dlg) {
        dlg.dispose();
    }

    public static final void btnSaveActionPerformed(JTextField ten, JTextField sdt, JTextField diachi) {
        try {
            String tenNCC = ten.getText();
            String sdtNCC = sdt.getText();
            String diaChi = diachi.getText();
            NhaCungCap ncc = new NhaCungCap(tenNCC, diaChi, sdtNCC);
            NhaCungCapDAO.insert(ncc);
        } catch (HibernateException ex) {
            JOptionPane.showMessageDialog(null, "Lỗi! Không thêm được.");
            return;
        }
        JOptionPane.showMessageDialog(null, "Thêm NCC thành công.");
    }
}
